package com.fzj.example.design.mediator;


import java.util.ArrayList;
import java.util.List;

/**
* @Description 房产中介
* @Author  fanzj
* @Date   2020/5/10 9:07 下午
* @Param
* @Return
* @Exception
*
*/
public class EstateMedium implements Medium {

    private List<Customer> customerList=new ArrayList<>();


    @Override
    public void register(Customer customer) {
        if(customerList.contains(customer)){
            return;
        }
        this.customerList.add(customer);
        customer.setMedium(this);
    }

    @Override
    public void relay(String from, String ad) {
        for(Customer ob:customerList)
        {
            String name=ob.getName();
            if(!name.equals(from))
            {
                ((Customer)ob).receive(from,ad);
            }
        }
    }
}
